package com.hc.bankonline.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hc.bankonline.services.BankOnlineservices;
import com.hc.bankonline.services.BankOnlineservicesImpl;

public class BankOnlineUpdatePwdServlet extends HttpServlet {

	private static final long serialVersionUID = 2283047168872217048L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		Map map = (Map) request.getSession().getAttribute("mapAcount");
		String loginAccount = (String) map.get("loginAccount");
		
		String loginPassword = request.getParameter("loginPassword");
		String newPassword = request.getParameter("newPassword");
		
		BankOnlineservices bankOnlineBiz = new BankOnlineservicesImpl();
		boolean result = bankOnlineBiz.updatePwdInfo(loginAccount,loginPassword,newPassword);
		
		if(result){
			System.out.println("密码修改成功!");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}else{
			System.out.println("密码修改失败!");
			request.getRequestDispatcher("changepwd.jsp").forward(request, response);
		}
	}
}
